package com.cloud.neo4j.business.neo4j.car.service.impl;

import com.alibaba.fastjson.JSON;
import com.cloud.neo4j.business.dto.result.ResultEntity;
import com.cloud.neo4j.business.neo4j.car.entity.PersonEntity;
import com.cloud.neo4j.business.neo4j.car.entity.business.PersonBaseEntity;
import com.cloud.neo4j.business.neo4j.car.repository.PersonRelationShipRepository;
import com.cloud.neo4j.business.neo4j.car.service.IPersonRelationShipService;
import org.neo4j.driver.Record;
import org.neo4j.driver.Records;
import org.neo4j.driver.Result;
import org.neo4j.driver.types.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cloud.neo4j.common.neo4j.Neo4jResponse.setNodeCov;

/**
 * 测试业务层
 * @date 2022-05-26
 * @author 刘房
 */
@Service
public class PersonRelationShipServiceImpl implements IPersonRelationShipService {

    @Autowired
    private PersonRelationShipRepository personRelationShipRepository;


    @Override
    public List<Map<String,Object>> getPersonRelationShipEntityAll(String name, String type, Integer number){
        Result result = personRelationShipRepository.findActenInPersonGtNumberByNameAndTypeAndNumber(name,type,number);
        List<Record> list = result.list();
//        result.forEach(map -> System.out.println(JSON.toJSONString(map)));
        //        List<Record> records = result.list();
        return null;
    }



    public static List<Map<String,Object>> getResultEntity(List<Record> list){
        List<Map<String,Object>> resultEntityList = new ArrayList<>();
        if(list.size() < 1) {
            return null;
        }
        /** 处理数据 */
        for (int i = 0; i < list.size(); i++) {
            Record record = list.get(i);
            Map<String,Object> resMap = new HashMap<>();
            resMap.put("startNode",setNodeCov(record.get("p").asNode()));
            resMap.put("number",(record.get("number").asInt()));
            resMap.put("endNode",setNodeCov(record.get("pw").asNode()));
            resultEntityList.add(resMap);
        }
        return resultEntityList;
    }

}
